package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.FileSignatureBoxStatus;
import com.ygxsk.carhome.response.FileSignatureManage;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-10-19  14:41
 * @Description:档案文件的签约适配器主页列表
 */
public class FileSignatureItemAdapter extends BaseQuickAdapter<FileSignatureManage, BaseViewHolder> {

    private int extra_jumpfrom_where;

    public FileSignatureItemAdapter(int layoutResId, @Nullable List<FileSignatureManage> data, int _extra_jumpfrom_where) {
        super(layoutResId, data);

        this.extra_jumpfrom_where = _extra_jumpfrom_where;

        addChildLongClickViewIds(R.id.textViewFileSignPartyBPhone);

//        addChildClickViewIds(//
//                R.id.textViewFileSignPartyBPhone,//拨打客户手机号的控件
//                R.id.roundTextViewButton_signature_qrcode,//销售员 生成签署二维码
//                R.id.roundTextViewButton_signature_edit,//销售员 填写
//                R.id.roundTextViewButton_signature_cancel,//销售员 作废合同
//                R.id.roundTextViewButton_signature_preview,//销售员 预览接口
//                R.id.roundTextViewButton_signature_permission,//销售员 发起审批
//
//                R.id.roundTextViewButton_signature_sure_manager,//管理层 确认发起电子合同
//                R.id.roundTextViewButton_signature_cancel_manager,//管理层 作废按钮
//                R.id.roundTextViewButton_signature_preview_manager,//管理层 预览按钮
//                R.id.roundTextViewButton_signature_edit_manager//管理层 填写，因为管理层也可以签署合同
//        );

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, FileSignatureManage fileSignatureManage) {

        if (fileSignatureManage != null) {

            //签约时间
            String createTime = fileSignatureManage.getCreateTime();
            //档案编号
            String createSerialNo = fileSignatureManage.getInformationNo();
            //合同模板--2023年10月30日15:45:14暂时改动为 店铺名称
            //String signTemplateName = fileSignatureManage.getSignTemplateName();

            //所在园区的名称
            String communityName = fileSignatureManage.getCommunityName();
            //店铺名称：
            String signTemplateName = fileSignatureManage.getShopInfoName();

            String resultShopName = "";

            if (!TextUtils.isEmpty(communityName)) {
                resultShopName = signTemplateName + StringUtils.getString(R.string.kongge0) + StringUtils.getString(R.string.bracket_left_small) + communityName + StringUtils.getString(R.string.bracket_right_small);
            } else {
                resultShopName = signTemplateName;
            }

            //乙方名称--也即是 客户名称
            String clientName = fileSignatureManage.getClientName();

            //客户手机号
            String clientPhone = fileSignatureManage.getClientPhone();

//             enum FileSignatureBoxStatus {
//                //审核状态   0填写中，1待审核  2通过  3不通过
//                AUDITSTATUS_FILL("0"),//
//                AUDITSTATUS_TO_BE_REVIEWED("1"),//
//                AUDITSTATUS_PASSED("2"),//
//                AUDITSTATUS_FAILED("3");//

            //档案状态  数值状态
            String auditStatus = fileSignatureManage.getAuditStatus();
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--auditStatus-->" + auditStatus);

            //档案状态  汉字状态
            String auditStatusInfo = "";

            if (!TextUtils.isEmpty(auditStatus)) {

                if (TextUtils.equals(auditStatus, FileSignatureBoxStatus.AUDITSTATUS_FILL.getIndex())) {

                    //填写中
                    auditStatusInfo = FileSignatureBoxStatus.AUDITSTATUS_FILL.getValue();

                } else if (TextUtils.equals(auditStatus, FileSignatureBoxStatus.AUDITSTATUS_TO_BE_REVIEWED.getIndex())) {

                    //待审核
                    auditStatusInfo = FileSignatureBoxStatus.AUDITSTATUS_TO_BE_REVIEWED.getValue();

                } else if (TextUtils.equals(auditStatus, FileSignatureBoxStatus.AUDITSTATUS_PASSED.getIndex())) {

                    //通过
                    auditStatusInfo = FileSignatureBoxStatus.AUDITSTATUS_PASSED.getValue();


                } else if (TextUtils.equals(auditStatus, FileSignatureBoxStatus.AUDITSTATUS_FAILED.getIndex())) {

                    //不通过
                    auditStatusInfo = FileSignatureBoxStatus.AUDITSTATUS_FAILED.getValue();


                }

            }


            //签约时间
            TextView textViewFileSignCreateTime = (TextView) baseViewHolder.getView(R.id.textviewfilesigncreatetime);
            //合同编号
            TextView textViewFileArchivesInDocment = (TextView) baseViewHolder.getView(R.id.textviewfilesignature);
            //模板名称
            TextView textViewFileSignTemplateName = (TextView) baseViewHolder.getView(R.id.textViewFileSignTemplateName);
            //乙方姓名
            TextView textViewFileSignPartyBName = (TextView) baseViewHolder.getView(R.id.textViewFileSignPartyBName);
            //乙方电话
            TextView textViewFileSignPartyBPhone = (TextView) baseViewHolder.getView(R.id.textViewFileSignPartyBPhone);
            //档案状态
            TextView textViewFileSignContractStatus = (TextView) baseViewHolder.getView(R.id.textViewFileSignContractStatus);

            //一条帮助横线用于在显示隐藏的时候用到
//          TextView textViewLineToptoButtons = (TextView) baseViewHolder.getView(R.id.textViewLineToptoButtons);

            //签约时间
            CommUtils.setText(textViewFileSignCreateTime, createTime);
            //档案编号
            CommUtils.setText(textViewFileArchivesInDocment, createSerialNo);
            //模板名称--2023年10月30日15:58:37改为店铺名称
            CommUtils.setText(textViewFileSignTemplateName, resultShopName);
            //乙方姓名,客户姓名
            CommUtils.setText(textViewFileSignPartyBName, clientName);
            //乙方电话
            CommUtils.setText(textViewFileSignPartyBPhone, clientPhone);
            //档案状态
            CommUtils.setText(textViewFileSignContractStatus, auditStatusInfo);

//            if (extra_jumpfrom_where == ExtraValue.VALUE_JUMPFROM_SIGNATURE_ACTIVITY_ONITEM_CLICK_INTO) {
//                //正常的管理页进入
//                linearLayoutTwoWrapButtons.setVisibility(View.VISIBLE);
//                textViewLineToptoButtons.setVisibility(View.VISIBLE);
//
//            } else if (extra_jumpfrom_where == ExtraValue.VALUE_JUMPFROM_SIGNATURE_HISTROY_ACTIVITY_ONITEM_CLICK_INTO) {
//
//                //历史记录进入
//                linearLayoutTwoWrapButtons.setVisibility(View.GONE);
//                textViewLineToptoButtons.setVisibility(View.GONE);
//            }

        }

    }
}
